package io.wdb.common.utils;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component(value="poiStyle")
@Scope(value="prototype")
public class PoiStyle {
	private HSSFCellStyle headStyle = null;
	private HSSFCellStyle cellStyle = null; 
	private HSSFCellStyle errorStyle = null;
	private HSSFCellStyle timeStyle = null;
	/**
	 * 
	 * @Method:headStyle
	 * @Description:表头样式
	 * @Time 2018年2月2日 下午5:59:59
	 * @author: Tom
	 * @param workbook
	 * @return
	 */
	public  HSSFCellStyle headStyle(Workbook workbook) {
		if(headStyle==null) {
			headStyle = (HSSFCellStyle) workbook.createCellStyle();
			headStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中    		
			HSSFFont font = (HSSFFont) workbook.createFont();
			font.setColor(HSSFColor.RED.index);
			headStyle.setFont(font);
		}
		return headStyle;
	}
	/**
	 * 
	 * @Method:normalBodyStyle
	 * @Description:正常内容样式
	 * @Time 2018年2月2日 下午6:00:25
	 * @author: Tom
	 * @param workbook
	 * @return
	 */
	public  HSSFCellStyle normalBodyStyle(Workbook workbook) {
		if(cellStyle==null) {
			cellStyle = (HSSFCellStyle) workbook.createCellStyle();   
			cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中    		
		}
		return cellStyle;
	}
	/**
	 * 
	 * @Method:errorBodyStyle
	 * @Description:警告内容样式
	 * @Time 2018年2月2日 下午6:01:09
	 * @author: Tom
	 * @param workbook
	 * @return
	 */
	public  HSSFCellStyle errorBodyStyle(Workbook workbook) {
		if(errorStyle==null) {
			errorStyle = (HSSFCellStyle) workbook.createCellStyle();    
			errorStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中    
			HSSFFont font = (HSSFFont) workbook.createFont();
			font.setColor(HSSFColor.RED.index);
			errorStyle.setFont(font);
		}
		return errorStyle;
	}
	/**
	 * 
	 * @Method:timeStyle
	 * @Description:时间样式
	 * @Time 2018年2月24日 下午4:25:58
	 * @author: Tom
	 * @param workbook
	 * @return
	 */
	public HSSFCellStyle timeStyle(Workbook workbook) {
		if(timeStyle==null) {
			timeStyle = (HSSFCellStyle) workbook.createCellStyle();   
			HSSFDataFormat format= (HSSFDataFormat) workbook.createDataFormat();
			timeStyle.setDataFormat(format.getFormat("yyyy-MM-dd HH:mm:ss"));
		}
		return timeStyle;
	}
}
